package comLibs.findingPath
{

	/**
	 *
	 * @author zihol.luo
	 * Holds a two-dimensional array of Nodes methods to mainpulate them, start node and end node for finding a path
	 */
	public class Grid
	{
		private var _startNode:Node;
		private var _endNode:Node;
		private var _nodes:Array;
		private var _numCols:int;
		private var _numRows:int;

		public function Grid(numCols:int, numRows:int)
		{
			_numCols=numCols;
			_numRows=numRows;
            _nodes=[];
			for (var i:int=0; i < _numCols; i++)
			{
				_nodes[i]=[];
				for (var j:int=0; j < _numRows; j++)
				{
					_nodes[i][j]=new Node(i, j);
				}
			}
		}

		//////////////////////
		//   public method
		/////////////////////
		/**
		 * returns the node at given coords.
		 * @param x
		 * @param y
		 * @return
		 *
		 */
		public function getNode(x:int, y:int):Node
		{
			return _nodes[x][y] as Node;
		}

		/**
		 * Sets the node at given coords as the end node.
		 * @param x
		 * @param y
		 *
		 */
		public function setEndNode(x:int, y:int):void
		{
			_endNode=_nodes[x][y] as Node;
		}

		/**
		 * Sets the node at given coords as the start node.
		 * @param x
		 * @param y
		 *
		 */
		public function setStartNode(x:int, y:int):void
		{
			_startNode=_nodes[x][y] as Node;
		}

		public function setWalkable(x:int, y:int, bool:Boolean):void
		{
			_nodes[x][y].walkable=bool;
		}

		////////////////////////
		/////	getters and setters
		/////////////////////////
		/**
		 * Returns the endNode.
		 * @return
		 *
		 */
		public function get endNode():Node
		{
			return _endNode;
		}

		/**
		 * Returns the startNode.
		 * @return
		 *
		 */
		public function get startNode():Node
		{
			return _startNode;
		}
		/**
		 * Returns the number of columns in the grid.
		 * @return 
		 * 
		 */
		public function get numCols():int
		{
			return _numCols;
		}
		/**
		 * Returns the number of rows in the grid. 
		 * @return 
		 * 
		 */		
		public function get numRows():int
		{
			return _numRows;
		}
	}
}
